#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include<QPen>
#include<QBrush>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    x=0;
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *)
{
    QPainter p(this);
   // QPainter p;
 //   p.begin(this);
    p.drawPixmap(0,0,width(),height(),QPixmap("../Image/bk.jpg"));
  //  p.end();

    //定义画笔
    QPen pen;
    pen.setWidth(5);//设置线宽
    pen.setColor(QColor(17,9,234));//RGB设置颜色
    pen.setStyle(Qt::DashDotLine);//设置风格

    //把画笔交给画家
    p.setPen(pen);
    //画直线
    p.drawLine(50,50,150,50);

    QBrush brush;
    brush.setColor(Qt::red);
    brush.setStyle(Qt::Dense1Pattern);
    p.setBrush(brush);

    //画矩形
    p.drawRect(150,150,100,50);

    //画笑脸
    p.drawPixmap(x, 180, 80, 80, QPixmap("../Image/face.png"));
}

void Widget::on_pushButton_clicked()
{
  x +=20;
  if(x > width())
  {
      x = 0;
  }
  update();
}
